import { useRequest } from 'ahooks';
import { GetDataItemInfo, GetPWorkItemComInfo } from '../../api/work';
import { Button, Space, Table, message } from 'antd';
// import { eventDatacolumns } from '../store';
import { useEffect } from 'react';
import { ColumnsType } from 'antd/lib/table';
import appState from '../../sotre';
// import { XDataGrid } from 'xinherc';

export const eventDatacolumns: ColumnsType<any> = [
  {
    title: 'No.',
    dataIndex: 'name',
    width: 40,
    align: 'center',
    render: (_, r, i) => {
      return i + 1;
    },
  },
  {
    title: '中文名称',
    dataIndex: 'FIELD_NAME',
  },
  {
    title: '字段名称',
    dataIndex: 'FIELD_CODE',
  },
  {
    title: '格式',
    dataIndex: 'FEILD_FORMAT',
    width: 100,
  },
  {
    title: '操作',
    width: 40,
    align: 'center',
    render: (_, op) => {
      return (
        <Button
          size="small"
          type="primary"
          onClick={async () => {
            const nameStr = op.FIELD_NAME + `{${op.FIELD_CODE}}`;
            await appState.factory.addEventData(nameStr);
            message.success('数据项添加成功');
          }}
        >
          添加
        </Button>
      );
    },
  },
];

const EventDataView = () => {
  const getPWorkItemComInfo = useRequest(GetDataItemInfo, { manual: true });
  // const [rowInfo,setRowInfo]
  useEffect(() => {
    getPWorkItemComInfo.run();
  }, []);
  return (
    <Table
      columns={eventDatacolumns}
      dataSource={getPWorkItemComInfo.data}
      size="small"
      bordered
      loading={getPWorkItemComInfo.loading}
      pagination={false}
    />
  );
};

export default EventDataView;
